<?php
namespace api\home\controller;

use api\user\model\MinerModel;
use api\common\controller\RestBaseController;
use think\Db;

class MinerController extends RestBaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * [获取矿机]
     */
    public function index()
    {
        $param = $this->request->param();

        $MinerModel  = new MinerModel();
        $map['where']['status'] = 1;
        $map['order']           = '-createtime';
        if (!empty($param['page'])) {
            $map['page'] = $param['page'];
        }
        if (!empty($param['miner_cat'])) {
            $map['where']['miner_cat'] = $param['miner_cat'];
        }
        $data = $MinerModel->getDatas($map);
        foreach($data as &$v){
            //今日库存
            $v['today'] = Db::name('user_miner')->where(['miner_id'=>$v['id']])->whereTime('createtime', 'd')->count();
            $v['today_limit'] = $v['day_limit'] - $v['today'];
            if($v['today_limit'] < 0){
                $v['today_limit'] = 0;
            }

        }
        $this->success('请求成功', ['list' => $data]);
    }

}
